/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package stuff;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import model.Item;

/**
 *
 * @author JArik
 */
public class CellRenderer extends JLabel implements TableCellRenderer{

    public CellRenderer()
    {
        this.setOpaque(true);
    }
    @Override
     public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus, int row, int column) {

         if (isSelected) {
           
           setForeground(table.getSelectionForeground());
           super.setBackground(table.getSelectionBackground());

         } else {
           setForeground(table.getForeground());
           setBackground(table.getBackground());
         }
           if(value instanceof Item)
           {
               Item it = (Item)value;
               this.setText(it.toTableString());
           }else
           {
             if(value != null)
               this.setText(value.toString());
           }
        return this;
    }

}
